package com.future.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.future.mapper.AdminMapper;
import com.future.mapper.UserMapper;
import com.future.po.User;
import com.future.service.AdminService;
import com.future.service.UserService;
import com.future.vo.QueryInfoVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author cjl
 * @date 2022/4/18 19:31
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class AdminSerbiceImpl extends ServiceImpl<UserMapper, User> implements AdminService {

    @Override
    public List<User> findUsers(QueryInfoVo queryInfo) {
        String username = queryInfo.getUsername();
        Integer pageSize = queryInfo.getPageSize();
        Integer pageNum = queryInfo.getPageNum();
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        if (!("".equals(username))){
            wrapper.like(User::getUsername,username);
        }

        Page<User> userPage = new Page<>(pageNum,pageSize);
        IPage<User> page = baseMapper.selectPage(userPage, wrapper);
        return page.getRecords();

    }
}
